import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wch/constant/resource_constant.dart';
import 'package:wch/utils/navigator_utils.dart';
import 'package:wch/widget/common_widget.dart';
import 'package:wch/widget/padding_widget.dart';

class SetWifiSuccessPage extends StatefulWidget {
  const SetWifiSuccessPage({super.key});

  @override
  State<SetWifiSuccessPage> createState() => _SetWifiSuccessPageState();
}

class _SetWifiSuccessPageState extends State<SetWifiSuccessPage> {
  int second = 3;

  Timer? secondTimer;
  Timer? delayPopTimer;
  @override
  void initState() {
    secondTimer = Timer.periodic(Duration(seconds: 1), (timer) {
      setState(() {
        second --;
      });
      if (second <= 0) {
        timer.cancel();
        delayPopTimer = Timer(Duration(milliseconds: 300), () {
          NavigatorUtil.pop(context);
        });
      }

    });
  }

  @override
  Widget build(BuildContext context) {
    return CommonScaffold(title: '配置成功', body: Container(
      color: themeBGC,
      margin: EdgeInsets.all(15.w),
      child: Container(
        width: ScreenUtil().screenWidth - 30.w,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(7.5.w))
        ),
        child: Column(
          children: [
            VerPadding(100.h),
            Image.asset(setWifiSuccessIcon, width: 80.w, height: 80.w,),
            VerPadding(30.h),
            Text('恭喜你，配置成功了！', style: TextStyle(
              fontWeight: FontWeight.w500,
              fontSize: 16,
              color: Color(0xFF3E3F42),
            ),),
            Expanded(child: Container()),
            Container(
              margin: EdgeInsets.symmetric(horizontal: 30.w),
              child: CommonBtn(
                callback: (){
                  if (secondTimer != null) {
                    secondTimer!.cancel();
                  }
                  if (delayPopTimer != null) {
                    delayPopTimer!.cancel();
                  }
                  NavigatorUtil.pop(context);
                }, title: '完成（$second秒）',
              ),
            ),
            VerPadding(50.h)
          ],
        ),
      ),
    ));
  }
}
